<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script>
    function getRandom(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }
    var random = getRandom(1, 10);
    while (true) {    // 死循环，利用break来跳出循环
      var num = prompt('请输入一个1~10的整数：');
      if (num === null) {
        break;
      } else if (num > random) {
        alert('你猜大了');
      } else if (num < random) {
        alert('你猜小了');
      } else {
        alert('恭喜你，猜对了');
        break;
      }
    }
  </script>
</body>
</html>